home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / libtiff / tif_msdos.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  142 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_msdos.c,v 1.5 92/11/09 11:00:23 sam Rel $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler
  7.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library MSDOS-specific Routines.
  31.  */
  32. #include "tiffiop.h"
  33. #if defined(__WATCOMC__) || defined(__BORLANDC__)
  34. #include <io.h>        /* for open, close, etc. function prototypes */
  35. #endif
  36.  
  37. static int
  38. DECLARE3(_tiffReadProc, void*, fd, char*, buf, u_long, size)
  39. {
  40.     return (read((int) fd, buf, size));
  41. }
  42.  
  43. static int
  44. DECLARE3(_tiffWriteProc, void*, fd, char*, buf, u_long, size)
  45. {
  46.     return (write((int) fd, buf, size));
  47. }
  48.  
  49. static long
  50. DECLARE3(_tiffSeekProc, void*, fd, long, off, int, whence)
  51. {
  52.     return (lseek((int) fd, off, whence));
  53. }
  54.  
  55. static int
  56. DECLARE1(_tiffCloseProc, void*, fd)
  57. {
  58.     return (close((int) fd));
  59. }
  60.  
  61. #include <sys/stat.h>
  62.  
  63. static long
  64. DECLARE1(_tiffSizeProc, void*, fd)
  65. {
  66.     struct stat sb;
  67.     return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
  68. }
  69.  
  70. static int
  71. DECLARE3(_tiffMapProc, void*, fd, char**, pbase, long*, psize)
  72. {
  73.     return (0);
  74. }
  75.  
  76. static void
  77. DECLARE3(_tiffUnmapProc, void*, fd, char*, base, long, size)
  78. {
  79. }
  80.  
  81. /*
  82.  * Open a TIFF file descriptor for read/writing.
  83.  */
  84. TIFF *
  85. DECLARE3(TIFFFdOpen, int, fd, const char*, name, const char*, mode)
  86. {
  87.     TIFF *tif;
  88.  
  89.     tif = TIFFClientOpen(name, mode,
  90.         (void*) fd,
  91.         _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
  92.         _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
  93.     if (tif)
  94.         tif->tif_fd = fd;
  95.     return (tif);
  96. }
  97.  
  98. /*
  99.  * Open a TIFF file for read/writing.
  100.  */
  101. TIFF *
  102. DECLARE2(TIFFOpen, const char*, name, const char*, mode)
  103. {
  104.     static const char module[] = "TIFFOpen";
  105.     int m, fd;
  106.  
  107.     m = _TIFFgetMode(mode, module);
  108.     if (m == -1)
  109.         return ((TIFF *)0);
  110.     fd = open(name, m|O_BINARY, 0666);
  111.     if (fd < 0) {
  112.         TIFFError(module, "%s: Cannot open", name);
  113.         return ((TIFF *)0);
  114.     }
  115.     return (TIFFFdOpen(fd, name, mode));
  116. }
  117.  
  118. #ifdef __GNUC__
  119. extern    char *malloc();
  120. extern    char *realloc();
  121. #else
  122. #include <malloc.h>
  123. #endif
  124.  
  125. void *
  126. DECLARE1(_TIFFmalloc, size_t, s)
  127. {
  128.     return (malloc(s));
  129. }
  130.  
  131. void
  132. DECLARE1(_TIFFfree, void*, p)
  133. {
  134.     free(p);
  135. }
  136.  
  137. void *
  138. DECLARE2(_TIFFrealloc, void*, p, size_t, s)
  139. {
  140.     return (realloc(p, s));
  141. }
  142.